package com.starsoft.quant.analysis;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.starsoft.mathlib.macd.MacdCaculator;
import com.starsoft.mathlib.macd.MacdReslult;
import com.starsoft.smdc.bean.SmdcMarketDaily;
import com.starsoft.smdc.bean.SmdcSecurity;
import com.starsoft.smdc.service.MarketDailyService;

@Service
public class IndicatorService {
	@Autowired
	MarketDailyService marketDailyService;
	
	public MacdReslult getMacd(SmdcSecurity security, int retCount, Date endDate, SmdcMarketDaily latestMarket){
		int priceCount = MacdCaculator.getPriceNumber(retCount);
		List<SmdcMarketDaily> markets = marketDailyService.getSomeBefore(security.getSecId(), priceCount, endDate);
		double[] prices = new double[markets.size()+1];
		for(int i=0;i<markets.size();i++){
			prices[markets.size()-i-1] = markets.get(i).getClosePrice();
		}
		prices[markets.size()] = latestMarket.getClosePrice();
		return MacdCaculator.caculate(prices, retCount);
	}

	public MacdReslult getMacd(SmdcSecurity security, int retCount, SmdcMarketDaily latestMarket){
		return null;
	}
	
}
